package com.itheima.activities.controller;

import com.itheima.activities.service.RedPacketService;
import com.itheima.entity.dto.RedPacketDto;
import com.itheima.entity.pojo.RedPacketList;
import com.itheima.entity.vo.RedPacketVo;
import com.itheima.entity.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author :wujunjie
 * createTime :2022-12-19 15:51
 * description :
 */
@RestController
@RequestMapping("/activitiesService/redpacket")
public class RedPacketController {
    @Autowired
    private RedPacketService redPacketService;

    @PostMapping()
    private Result insertRedPacket(@RequestBody RedPacketDto redPacketDto){
        Boolean insert=redPacketService.insertRedPacket(redPacketDto);
        if (insert){
            return Result.success();
        }
        return Result.error();
    }

    /**
     * 获取红包活动
     * @return
     */
    @GetMapping("/allRedPacket")
    private Result getAllRedPacket(){
        List<RedPacketVo> redPacketVos=redPacketService.getAllRedPacket();
        return Result.success(redPacketVos);
    }

    /**
     * 抢红包接口
     * @param redPacketId 活动ID
     * @return Result
     */
    @GetMapping()
    private Result getRedPacketList(@RequestParam(value = "redPacketId") String redPacketId){
        RedPacketList insert=redPacketService.getRedPacketList(redPacketId);
        return Result.success(insert.getMoney());
    }

}
